package plgdb

import (
	"dgo/MyProj/PrjDBUtils"
	"gitee.com/ymofen/supervalue"
)

type PlgDBExecParam struct {
	HttpReq      *PlgDBRequest
	ResID        string
	DataSourceid string
	DBName       string
	SingleName   string

	trans    bool
	tracesql int

	Req             *wrapper.SuperValue
	Resp            *wrapper.SuperValue
	DBResConf       *wrapper.SuperValue
	Args            *wrapper.SuperValue
	Dao             *PrjDBUtils.DAOHelper
	GetParamValFunc func(sender interface{}, key string) (bool, interface{})
}

func NewDBExecParma() *PlgDBExecParam {
	rval := &PlgDBExecParam{}
	return rval
}

func (this *PlgDBExecParam) Close() error {
	if this.Dao != nil {
		this.Dao.Close()
		this.Dao = nil
	}
	return nil
}

func (this *PlgDBExecParam) GetParamVal(key string) (ok bool, val interface{}) {
	ok = false
	if this.HttpReq.OnGetParamValFunc != nil {
		ok, val = this.HttpReq.OnGetParamValFunc(this, key)
	}
	if !ok && this.GetParamValFunc != nil {
		ok, val = this.GetParamValFunc(this, key)
	}

	return
}

func (this *PlgDBExecParam) ReqStringByName(key string, def string) string {
	if this.Req == nil {
		return def
	}
	return this.Req.StringByName(key, def)
}

func (this *PlgDBExecParam) ReqIntByName(key string, def int) int {
	if this.Req == nil {
		return def
	}
	return this.Req.IntByName(key, def)
}
